package com.acme.bankapp.domain.bank;

import java.io.Serializable;

import com.acme.bankapp.exceptions.bank.NotEnoughFundsException;

public class SavingsAccount extends AbstractAccount{

	public SavingsAccount(int initialValue) throws IllegalArgumentException {
		super(initialValue);
	}

	public void withdraw(int sum) throws NotEnoughFundsException {
		if (this.getBalance() >= sum) {
			this.setBalance(this.getBalance() - sum);
		} else {
			throw new NotEnoughFundsException(this);
		}
	}

	public int maximumAmountToWithdraw() {
		return this.getBalance();
	}

	public boolean equals(Object object) {
		if (this == object) {
			return true;
		}
		if (object == null) {
			return false;
		}
		if (this.getClass() != object.getClass()) {
			return false;
		}
		SavingsAccount ob = (SavingsAccount) object;
		if (this.getBalance() == ob.getBalance()) {
			return true;
		} else {
			return false;
		}
	}

	public int hashCode() {
		int code = 11;
		int k = 7;
		code = k * code + this.getBalance();
		return code;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer("Balance of SavingsAccount is ");
		sb.append(AbstractAccount.decimalValue(this.getBalance()));
		sb.append("\n");
		return sb.toString();
	}
}
